package edu.nf.relaxenjoy.web.controller.app;

import edu.nf.relaxenjoy.common.result.IPage;
import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.common.validator.ValidatorUtils;
import edu.nf.relaxenjoy.common.validator.group.DefaultGroup;
import edu.nf.relaxenjoy.domain.dto.CommentDTO;
import edu.nf.relaxenjoy.domain.vo.CommentVo;
import edu.nf.relaxenjoy.service.CommentService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/comment")
@Api(tags="评论模块")
public class CommentController extends BaseController {

    private final CommentService commentService;


    /**
     * 得到当前图片下的所有一级评论
     *
     * @param page
     * @param limit
     * @param mid
     * @param uid
     * @return
     */
    @RequestMapping("getAllOneCommentByImgId/{page}/{limit}")
    public ResultVO getAllOneCommentByImgId(@PathVariable long page, @PathVariable long limit, @RequestParam("id") Long mid, @RequestParam("id") Long uid) {
        IPage<CommentVo> pageInfo = commentService.getAllOneCommentByPostId(page, limit, mid, uid);
        return success(pageInfo);
    }

    /**
     * 得到评论信息
     *
     * @param id
     * @return
     */
    @RequestMapping("getComment")
    public ResultVO getComment(@RequestParam("id") Long id) {
        return success(commentService.getById(id));
    }

    /**
     * 增加一条评论
     *
     * @param commentDTO
     * @return
     */
    @RequestMapping("addComment")
    public ResultVO addComment(@RequestBody CommentDTO commentDTO) {
        ValidatorUtils.validateEntity(commentDTO, DefaultGroup.class);
        CommentVo commentVo = commentService.addComment(commentDTO);
        return success(commentVo);
    }

    /**
     * 分页查询一级评论下的所有二级评论
     *
     * @param page
     * @param limit
     * @param id
     * @param uid
     * @return
     */
    @RequestMapping("getAllTwoCommentByOneId/{page}/{limit}")
    public ResultVO getAllTwoCommentByOneId(@PathVariable long page, @PathVariable long limit, @RequestParam("id") Long id, @RequestParam("uid") Long uid) {
        IPage<CommentVo> pageInfo = commentService.getAllTwoCommentByOneId(page, limit, id, uid);
        return success(pageInfo);
    }

    /**
     * 得到当前一级评论下的所有二级评论
     *
     * @param id
     * @return
     */
    @RequestMapping("getAllTwoComment")
    public ResultVO getAllTwoComment(@RequestParam("id") Long id, @RequestParam("uid") Long uid) {
        List<CommentVo> pageInfo = commentService.getAllTwoComment(id, uid);
        return success(pageInfo);
    }

    /**
     * 查看所有回复的评论
     *
     * @param page
     * @param limit
     * @param uid
     * @return
     */
    @RequestMapping("getAllReplyComment/{page}/{limit}")
    public ResultVO getAllReplyComment(@PathVariable long page, @PathVariable long limit, @RequestParam("uid") Long uid) {
        List<CommentVo> commentVoList = commentService.getAllReplyComment(page, limit, uid);
        return success(commentVoList);
    }

    /**
     * 得到所有的一级评论并携带一个二级评论
     *
     * @param page
     * @param limit
     * @param mid
     * @param uid
     * @return
     */
    @RequestMapping("getAllComment/{page}/{limit}")
    public ResultVO getAllComment(@PathVariable long page, @PathVariable long limit, @RequestParam("mid") Long mid, @RequestParam("uid") Long uid) {
        IPage<CommentVo> pageInfo = commentService.getAllComment(page, limit, mid, uid);
        return success(pageInfo);
    }


    /**
     * 跳转评论
     * @param id
     * @param mid
     * @param uid
     * @return
     */
    @RequestMapping("scrollComment")
    public ResultVO scrollComment(@RequestParam("id") Long id, @RequestParam("mid") Long mid, @RequestParam("uid") Long uid){
        Map<String,Object> resMap= commentService.scrollComment(id, mid, uid);
        return success(resMap);
    }

    @RequestMapping("delComment")
    public ResultVO delComment(@RequestParam("id") Long id) {
        commentService.delComment(id);
        return success();

    }

}
